<template>
  <div>
    <h3 class="h3-title">查询配置</h3>
    <pd-dialog :visible.sync="queryBtnDialog">
      暂无
    </pd-dialog>
    <h4>按钮</h4>
    <el-button class="filter-item" disabled type="primary" icon="el-icon-search">
      搜索
    </el-button>
    <el-button type="primary" disabled icon="el-icon-plus" circle @click="queryBtnDialog = true" />
    <h4>字段</h4>
    <el-table :data="listConfig.queryOptions.cols">
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column label="字段名">
        <template slot-scope="scope">
          <el-input v-model="scope.row.field" />
        </template>
      </el-table-column>
      <el-table-column label="标题">
        <template slot-scope="scope">
          <el-input v-model="scope.row.title" />
        </template>
      </el-table-column>
      <el-table-column label="类型">
        <template slot-scope="scope">
          <el-select v-model="scope.row.type" placeholder="请选择">
            <el-option
              v-for="item in queryOptionsColsType"
              :key="item"
              :label="item"
              :value="item"
            />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="数据字典类型">
        <template slot-scope="scope">
          <el-input v-model="scope.row.dictType" />
        </template>
      </el-table-column>
    </el-table>
    <h3 class="h3-title">表格配置</h3>
    <el-button @click="listConfig.tableOptions.cols.push({})">增加一行</el-button>
    <el-table :data="listConfig.tableOptions.cols">
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column label="字段名">
        <template slot-scope="scope">
          <el-input v-model="scope.row.field" />
        </template>
      </el-table-column>
      <el-table-column label="标题">
        <template slot-scope="scope">
          <el-input v-model="scope.row.title" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { saveData, getMenuConfig } from '@/api/menu'

var _this
export default {
  name: 'ListConfig',
  props: {
    menuId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      queryBtnDialog: false,
      listConfig: this.listConfigTemp(),
      queryOptionsColsType: ['input', 'dict'],
      pdButtomAttrs: ['text', 'type']
    }
  },
  created() {
    _this = this
    getMenuConfig(this.menuId).then(res => {
      const { data } = res
      _this.listConfig = data.listConfig && JSON.parse(data.listConfig) || this.listConfigTemp()
    })
  },
  methods: {
    addQueryBtn() {

    },
    listConfigTemp() {
      return {
        tableOptions: {
          url: 'user/list',
          page: true,
          cols: [
            {
              field: '',
              title: ''
            }
          ]
        }
      }
    },
    save() {
      saveData({
        id: this.menuId,
        listConfig: JSON.stringify(this.listConfig)
      }).then(res => {
        _this.$emit('save-callback')
      })
    }
  }
}
</script>

<style>
  .h3-title {
    border-left: 5px solid #0092EE;padding-left: 10px
  }
  .el-dialog__body {
    padding: 0px 20px;
  }
</style>
